from mcp.server.fastmcp import FastMCP
import math

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("Modular Exponentiation Server")

@mcp.tool()
def modular_exponentiation(base: int, exponent: int, modulus: int) -> int:
    """
    大数模幂运算
    :param base: 底数
    :param exponent: 指数
    :param modulus: 模数
    :return: (base^exponent) mod modulus
    """
    if modulus == 1:
        return 0
    result = 1
    base = base % modulus
    while exponent > 0:
        if exponent % 2 == 1:
            result = (result * base) % modulus
        exponent = exponent >> 1
        base = (base * base) % modulus
    return result

if __name__ == "__main__":
    mcp.run()